// pages/shouquan/shouquan.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  getinfo(res){
    console.log(res)
    var headimg = res.detail.rawData
    var imgjson = JSON.parse(headimg)
    app.globalData.userInfo = imgjson
    wx.setStorageSync('headimg', imgjson)
    console.log('app.js里的信息,app.globalData.userInfo',app.globalData.userInfo)

    wx.login({
      //获取code
      success: function (res) {
        const APP_ID ='wxe329ad2878856a4c'
        const APP_SECRET ='5dc296468d2217287361a94f31dcca55'
          wx.request({
            url:'https://www.juquduo.com/get_user_info',
            
            data: {appId: APP_ID,secret:APP_SECRET,jsCode:res.code,grantType:'authorization_code'},
            method: 'GET',
            success: function (res){
              console.log(res.data);
              var openid = JSON.parse(res.data).openid //返回openid
              console.log('openid为' + openid);
              wx.setStorageSync('openid', openid)
              wx.request({
                url: 'https://www.juquduo.com/login',
                data:{
                  openid:openid,
                  avatar:app.globalData.userInfo.avatarUrl,
                  nickName:app.globalData.userInfo.nickName
                },
                success(resdata){
                  console.log(resdata)
                }
              })
            }
            
          })
        }})
    wx.navigateBack({
      delta: 1,
    })
  },

  onReady: function () {

  },

  onShow: function () {

  }

})